﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    xmlns:converters="clr-namespace:ICSharpCode.Data.EDMDesigner.Core.UI.Converters"
    xmlns:localControlsCSDLType="clr-namespace:ICSharpCode.Data.EDMDesigner.Core.UI.UserControls.CSDLType">

    <converters:ExpanderHeightConverter x:Key="ExpanderHeightConverter" />
    
    <Style x:Key="ExpanderToggleButtonStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">            
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <ContentPresenter x:Name="content" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
						    Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 
							RecognizesAccessKey="True" />
                        <StackPanel x:Name="arrow" Grid.Column="1" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Right">
                            <StackPanel.LayoutTransform>
                                <RotateTransform />
                            </StackPanel.LayoutTransform>
                            <Path Data="M0,0L3,3 6,0" Stroke="#FF666666" StrokeThickness="2" />
                            <Path Data="M0,0L3,3 6,0" Stroke="#FF666666" StrokeThickness="2" />
                        </StackPanel>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation To="180" Storyboard.TargetName="arrow" Storyboard.TargetProperty="LayoutTransform.Angle" Duration="0:00:00.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation To="0" Storyboard.TargetName="arrow" Storyboard.TargetProperty="LayoutTransform.Angle" Duration="0:00:00.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="arrow" Property="Opacity" Value="0.3" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style x:Key="ExpanderHeaderFocusVisual">
		<Setter Property="Control.Template">
			<Setter.Value>
				<ControlTemplate>
					<Border>
						<Rectangle SnapsToDevicePixels="true" Margin="0" Stroke="Black" StrokeDashArray="1 2" StrokeThickness="1"/>
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
    
	<Style TargetType="{x:Type localControlsCSDLType:TypeBaseExpander}">
		<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
		<Setter Property="Background" Value="Transparent"/>
		<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
		<Setter Property="VerticalContentAlignment" Value="Stretch"/>
		<Setter Property="BorderBrush" Value="Transparent"/>
		<Setter Property="BorderThickness" Value="1"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type Expander}">
					<Border x:Name="bdExpander" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" CornerRadius="8" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Opacity="{TemplateBinding Opacity}">
						<DockPanel>
							<Grid x:Name="grdHeader" DockPanel.Dock="Top" Margin="1">
                                <ToggleButton Grid.Column="1" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ExpanderToggleButtonStyle}">
                                    <ContentControl HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" x:Name="HeaderSite" Content="{TemplateBinding Header}" />
                                </ToggleButton>
                            </Grid>
                            <Grid x:Name="expandSite" DockPanel.Dock="Bottom">
                                <Grid.Height>
                                    <MultiBinding Converter="{StaticResource ExpanderHeightConverter}">
                                        <Binding Path="ActualHeight" ElementName="expandSiteContent" />
                                        <Binding Path="Tag" RelativeSource="{RelativeSource Self}" />
                                    </MultiBinding>
                                </Grid.Height>
                                <Grid.Tag>
                                    <system:Double>0.0</system:Double>
                                </Grid.Tag>
                                <ScrollViewer VerticalScrollBarVisibility="Hidden" HorizontalScrollBarVisibility="Hidden">
                                    <ContentPresenter Name="expandSiteContent" Focusable="False"
    									HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
    									VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
    									ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
    									Content="{TemplateBinding ContentControl.Content}" />
                                </ScrollViewer>
                            </Grid>
						</DockPanel>
					</Border>
					<ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation To="1.0" Storyboard.TargetName="expandSite" Storyboard.TargetProperty="Tag" Duration="0:00:00.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation To="0" Storyboard.TargetName="expandSite" Storyboard.TargetProperty="Tag" Duration="0:00:00.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
						<Trigger Property="IsEnabled" Value="false">
							<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
						</Trigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

</ResourceDictionary>